package net.gz01.wallet.web.controller.api.sdk.client.authForfadada;

import net.gz01.wallet.web.controller.api.sdk.client.common.FddClient;
import net.gz01.wallet.web.controller.api.sdk.util.crypt.FddEncryptTool;
import net.gz01.wallet.web.controller.api.sdk.util.http.HttpsUtil;

public class GetFileForUUID extends FddClient {
    public GetFileForUUID(String appId, String secret, String version, String url) {
        super(appId, secret, version, url);
    }
    /**
     * 通过uuid下载文件地址
     * @return
     */
    public String getFileForUUIDUrl() {
        return super.getUrl() + "get_file.api";
    }

    /**
     * 通过uuid 下载文件接口
     * @date: 2018年12月23日
     * @param uuid 查询实名认证结果时返回
     *
     * @return
     */
    public String invokeFileForUUID(String uuid) {
            String timeStamp = HttpsUtil.getTimeStamp();
            StringBuilder sb = new StringBuilder(this.getFileForUUIDUrl());
            try {
                String msgDigest;
                // Base64(SHA1(app_id+md5(transaction_id+timestamp)+SHA1(app_secret+ uuid)))
                String sha1 = FddEncryptTool.sha1(super.getAppId()
                        + FddEncryptTool.md5Digest(timeStamp)
                        + FddEncryptTool.sha1(super.getSecret() + uuid));
                msgDigest = new String(FddEncryptTool.Base64Encode(sha1.getBytes()));

                sb.append("?app_id=").append(super.getAppId());
                sb.append("&v=").append(super.getVersion());
                sb.append("&timestamp=").append(timeStamp);
                sb.append("&uuid=").append(uuid);
                sb.append("&msg_digest=").append(msgDigest);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
            return sb.toString();
        }
    }
